e use "$data_out/provider_propensity.dta", clear





*merge indicators for depresson
merge 1:m pid_pde encdate using "$data_out/depression_scripts",nogen keep(1 3)

rename subsample depression
recode depression .=0

label var propensity "Physician Propensity to Prescribe Opioids"
label var age "Age"
label var age_bin "Age Bin"
	label define age_labels 10 "Under 20" 20 "20-39" 30 "30-39" 40 "40-49" 50 "50-59" 60 "60-69" 70 "70+"
	label values age_bin age_labels
label var race_white "Race - White"
label var college "Education - College Degree"
label var female "Female"
label var junior_enlisted "Rank - Junior"
label var married "Marital Status - Married"
label var longevity "Military Tenure (Yrs)"
label var depression "Depression or Anxiety"
label var afqt_pct "Armed Forces Qualificaiton Test Percentile"

			cap postclose balance
			postfile balance str16 Variable Mean Coefficient Std_Error p_value   using "$plotdir/balance_continuous.dta", replace

foreach var of varlist  age race_white female junior_enlisted college married longevity depression afqt_p { 
			eststo balance: reg `var'  propensity ,  cluster(provID)
			estadd ysumm, replace
		
			post balance ("`var'") (e(ymean)) (_b[propensity]) (_se[propensity]) (2*normal(-abs(_b[propensity]/_se[propensity])))
			
			}

	postclose balance
	
				cap postclose balance
			postfile balance str16 Variable  Coefficient Std_Error p_value   using "$plotdir/balance_binary.dta", replace

foreach var of varlist  age race_white female junior_enlisted college married longevity depression  afqt_p { 
	eststo balance_`var'_Q: reg `var'  above  if inlist(quartile,1,4), cluster(provID)
			
		
			post balance ("`var'")  (_b[above]) (_se[above]) (2*normal(-abs(_b[above]/_se[above])))
			
			}

	postclose balance
	

			cap postclose balance
			postfile balance str16 Variable Mean Coefficient Std_Error p_value   using "$plotdir/balance_continuousFE.dta", replace

foreach var of varlist  age race_white female junior_enlisted college married longevity depression afqt_p { 
			eststo balance: reghdfe `var'  propensity , absorb(hym hd) cluster(provID)
			estadd ysumm, replace
		
			post balance ("`var'") (e(ymean)) (_b[propensity]) (_se[propensity]) (2*normal(-abs(_b[propensity]/_se[propensity])))
			
			}

	postclose balance
	
				cap postclose balance
			postfile balance str16 Variable  Coefficient Std_Error p_value   using "$plotdir/balance_binaryFE.dta", replace

foreach var of varlist  age race_white female junior_enlisted college married longevity depression  afqt_p { 
	eststo balance_`var'_Q: reghdfe `var'  above  if inlist(quartile,1,4), absorb(hym hd) cluster(provID)
			
		
			post balance ("`var'")  (_b[above]) (_se[above]) (2*normal(-abs(_b[above]/_se[above])))
			
			}

	postclose balance




//eichmeyer and zhang table



eststo balance_script: reg ed_prescription age race_white female junior_enlisted college married longevity depression afqt_p,  cluster(provID)

eststo balance_propensity: reg propensity age race_white female junior_enlisted college married longevity depression afqt_p, cluster(provID)


#delimit ;
	//word
esttab balance_script balance_propensity using "EZ_Table.rtf" , 
	replace label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(N F, 
	fmt(%-9.0fc %-9.2fc)
	label("Observations" "F-Statistic"))
	mtitles("ED Prescription" "Residualized Instrument")
	noconstant nobaselevels
	title(Balance Table for Continuous Instrument)
	compress;
	

#delimit cr
